package com.will.txj.common.utils;

import javax.servlet.http.HttpServletRequest;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.net.InetAddress;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.net.UnknownHostException;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Base64;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringUtil {

    /**
     * sql防注入正则表达式
     * \\b  表示 限定单词边界  比如  select 不通过   1select则是可以的
     */
    public static final String reg = "(?:')|(?:--)|(/\\*(?:.|[\\n\\r])*?\\*/)|"
            + "(\\b(select|update|union|and|or|delete|insert|trancate|char|into|substr|ascii|declare|exec|count|master|into|drop|execute)\\b)";

    // 有效
    public static final int EFFECTIVE = 0;

    // 无效
    public static final int INVALID = 1;

    // 执行未开始
    public static final int EXECUTE_NOT_BEGINNING = 0;

    // 执行中
    public static final int EXECUTING = 1;

    // 执行成功
    public static final int EXECUTE_SUCCESS = 2;

    // 执行失败
    public static final int EXECUTE_ERROR = 3;

    // 未初始化
    public static final int UNINITIALIZED = 1;

    // 已初始化
    public static final int INITIALIZATION = 2;

    // 验证式
    public static final int TYPE_VERIFY = 1;

    // 交互式
    public static final int TYPE_INTERACTIVE = 2;

    // 探索式
    public static final int TYPE_EXPLORE = 3;


    /**
     * 判断字符串为空
     */
    public static boolean isEmptyToString(String str) {
        if ("".equals(str) || str == null || "null".equals(str.toLowerCase())) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 判断字符串不为空
     */
    public static boolean isNotEmptyToString(String str) {
        return !isEmptyToString(str);
    }


    /**
     * 自动生成32位的UUid
     *
     * @return
     */
    public static String getUUID() {
        return UUID.randomUUID().toString().replace("-", "");
    }

    /**
     * 获取客户端IP
     *
     * @param request
     * @return
     */
    public static String getIpAdrress(HttpServletRequest request) {
        String ip = request.getHeader("x-forwarded-for");
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("Proxy-Client-IP");
        }

        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("WL-Proxy-Client-IP");
        }

        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("HTTP_CLIENT_IP");
        }

        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("HTTP_X_FORWARDED_FOR");
        }

        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getRemoteAddr();
        }

        if (ip != null && ip.indexOf(",") != -1) {
            String[] ipWithMultiProxy = ip.split(",");

            for (int i = 0; i < ipWithMultiProxy.length; ++i) {
                String eachIpSegement = ipWithMultiProxy[i];
                if (!"unknown".equalsIgnoreCase(eachIpSegement)) {
                    ip = eachIpSegement;
                    break;
                }
            }
        }

        //根据网卡取本机配置的IP
        if (ip.equals("127.0.0.1") || ip.equals("0:0:0:0:0:0:0:1")) {
            try {
                InetAddress inet = InetAddress.getLocalHost();
                ip = inet.getHostAddress();
            } catch (UnknownHostException e) {
                e.printStackTrace();
            }
        }

        return ip;
    }

    /**
     * 去除字符串中的回车、换行符、制表符
     *
     * @param str
     * @return
     */
    public static String replaceBlank(String str) {
        String dest = "";
        if (str != null) {
            Pattern p = Pattern.compile("\t|\r|\n");
            Matcher m = p.matcher(str);
            dest = m.replaceAll(" ");
        }
        return dest;
    }

    /**
     * sql防注入
     */
    public static boolean isValid(String str) {
        Pattern sqlPattern = Pattern.compile(StringUtil.reg, Pattern.CASE_INSENSITIVE);
        if (sqlPattern.matcher(str).find()) {
            System.out.println("未能通过过滤器：str=" + str);
            return false;
        }
        return true;
    }

    public static final String module = StringUtil.class.getName();

    public static String internString(String value) {
        return value != null ? value.intern() : null;
    }

    /**
     * Replaces all occurances of oldString in mainString with newString
     *
     * @param mainString The original string
     * @param oldString  The string to replace
     * @param newString  The string to insert in place of the old
     * @return mainString with all occurances of oldString replaced by newString
     */
    public static String replaceString(String mainString, String oldString, String newString) {
        if (mainString == null) {
            return null;
        }
        if (oldString == null || oldString.length() == 0) {
            return mainString;
        }
        if (newString == null) {
            newString = "";
        }

        int i = mainString.lastIndexOf(oldString);

        if (i < 0) return mainString;

        StringBuilder mainSb = new StringBuilder(mainString);

        while (i >= 0) {
            mainSb.replace(i, i + oldString.length(), newString);
            i = mainString.lastIndexOf(oldString, i - 1);
        }
        return mainSb.toString();
    }

    /**
     * Creates splitString method .
     *
     * @return mainString with all occurances of oldString replaced by newString
     * @date 20100330
     * @author zhangfe
     */
    public static String[] splitString(String source, String split) {
        List<String> splitList = null;
        if (source != null && !source.equals("")) {
            splitList = new ArrayList<>();
            StringBuffer nowStr = new StringBuffer(source);
            while (nowStr.toString().indexOf(split) != -1) {
                splitList.add(nowStr.toString().substring(0, nowStr.toString().indexOf(split)));
                nowStr = new StringBuffer(nowStr.toString().substring(nowStr.toString().indexOf(split) + split.length()));
            }
            splitList.add(nowStr.toString());
        }
        String[] splitArray = null;
        if (splitList != null && splitList.size() > 0) {
            splitArray = new String[splitList.size()];
            for (int i = 0; i < splitList.size(); i++) {
                splitArray[i] = splitList.get(i);
            }
        }
        return splitArray;
    }

    /**
     * Creates a single string from a List of strings seperated by a delimiter.
     *
     * @param list  a list of strings to join
     * @param delim the delimiter character(s) to use. (null value will join with no delimiter)
     * @return a String of all values in the list seperated by the delimiter
     */
    public static String join(List<String> list, String delim) {
        if (list == null || list.size() < 1)
            return null;
        StringBuilder buf = new StringBuilder();
        Iterator<String> i = list.iterator();

        while (i.hasNext()) {
            buf.append(i.next());
            if (i.hasNext())
                buf.append(delim);
        }
        return buf.toString();
    }

    /**
     * Splits a String on a delimiter into a List of Strings.
     *
     * @param str   the String to split
     * @param delim the delimiter character(s) to join on (null will split on whitespace)
     * @return a list of Strings
     */
    public static List<String> split(String str, String delim) {
        List<String> splitList = null;
        StringTokenizer st = null;

        if (str == null)
            return splitList;

        if (delim != null)
            st = new StringTokenizer(str, delim);
        else
            st = new StringTokenizer(str);

        if (st != null && st.hasMoreTokens()) {
            splitList = new ArrayList();

            while (st.hasMoreTokens())
                splitList.add(st.nextToken());
        }
        return splitList;
    }

    /**
     * Encloses each of a List of Strings in quotes.
     *
     * @param list List of String(s) to quote.
     */
    public static List<String> quoteStrList(List<String> list) {
        List<String> tmpList = list;

        list = new ArrayList();
        for (String str : tmpList) {
            str = "'" + str + "''";
            list.add(str);
        }
        return list;
    }

    /**
     * Creates a Map from an encoded name/value pair string
     *
     * @param str  The string to decode and format
     * @param trim Trim whitespace off fields
     * @return a Map of name/value pairs
     */
    public static Map<String, String> strToMap(String str, boolean trim) {
        if (str == null) return null;
        Map<String, String> decodedMap = new HashMap<String, String>();
        List<String> elements = split(str, "|");

        for (String s : elements) {
            List<String> e = split(s, "=");

            if (e.size() != 2) {
                continue;
            }
            String name = e.get(0);
            String value = e.get(1);
            if (trim) {
                if (name != null) {
                    name = name.trim();
                }
                if (value != null) {
                    value = value.trim();
                }
            }

            try {
                decodedMap.put(URLDecoder.decode(name, "UTF-8"), URLDecoder.decode(value, "UTF-8"));
            } catch (UnsupportedEncodingException e1) {
//                Debug.logError(e1, module);
            }
        }
        return decodedMap;
    }

    /**
     * Creates a Map from an encoded name/value pair string
     *
     * @param str The string to decode and format
     * @return a Map of name/value pairs
     */
    public static Map<String, String> strToMap(String str) {
        return strToMap(str, false);
    }

    /**
     * Creates an encoded String from a Map of name/value pairs (MUST BE STRINGS!)
     *
     * @param map The Map of name/value pairs
     * @return String The encoded String
     */
    public static String mapToStr(Map<? extends Object, ? extends Object> map) {
        if (map == null) return null;
        StringBuilder buf = new StringBuilder();
        boolean first = true;

        for (Map.Entry<? extends Object, ? extends Object> entry : map.entrySet()) {
            Object key = entry.getKey();
            Object value = entry.getValue();

            if (!(key instanceof String) || !(value instanceof String))
                continue;
            String encodedName = null;
            try {
                encodedName = URLEncoder.encode((String) key, "UTF-8");
            } catch (UnsupportedEncodingException e) {
            }
            String encodedValue = null;
            try {
                encodedValue = URLEncoder.encode((String) value, "UTF-8");
            } catch (UnsupportedEncodingException e) {
//                Debug.logError(e, module);
            }

            if (first)
                first = false;
            else
                buf.append("|");

            buf.append(encodedName);
            buf.append("=");
            buf.append(encodedValue);
        }
        return buf.toString();
    }

    /**
     * Reads a String version of a Map (should contain only strings) and creates a new Map
     *
     * @param s String value of a Map ({n1=v1, n2=v2})
     * @return new Map
     */
    public static Map<String, String> toMap(String s) {
        Map<String, String> newMap = new HashMap<String, String>();
        if (s.startsWith("{") && s.endsWith("}")) {
            s = s.substring(1, s.length() - 1);
            String[] entries = s.split("\\,\\s");
            for (String entry : entries) {
                String[] nv = entry.split("\\=");
                newMap.put(nv[0], nv[1]);
            }
        } else {
            throw new IllegalArgumentException("String is not from Map.toString()");
        }

        return newMap;
    }

    /**
     * Reads a String version of a List (should contain only strings) and creates a new List
     *
     * @param s String value of a Map ({n1=v1, n2=v2})
     * @return new List
     */
    public static List<String> toList(String s) {
        List<String> newList = new ArrayList<String>();
        if (s.startsWith("[") && s.endsWith("]")) {
            s = s.substring(1, s.length() - 1);
            String[] entries = s.split("\\,\\s");
            for (String entry : entries) {
                newList.add(entry);
            }
        } else {
            throw new IllegalArgumentException("String is not from List.toString()");
        }

        return newList;
    }

    /**
     * Reads a String version of a Set (should contain only strings) and creates a new Set
     *
     * @param s String value of a Map ({n1=v1, n2=v2})
     * @return new List
     */
    public static Set<String> toSet(String s) {
        Set<String> newSet = new HashSet<String>();
        if (s.startsWith("[") && s.endsWith("]")) {
            s = s.substring(1, s.length() - 1);
            String[] entries = s.split("\\,\\s");
            for (String entry : entries) {
                newSet.add(entry);
            }
        } else {
            throw new IllegalArgumentException("String is not from Set.toString()");
        }

        return newSet;
    }

    /**
     * Create a Map from a List of keys and a List of values
     *
     * @param keys   List of keys
     * @param values List of values
     * @return Map of combined lists
     * @throws IllegalArgumentException When either List is null or the sizes do not equal
     */
    public static <K, V> Map<K, V> createMap(List<K> keys, List<V> values) {
        if (keys == null || values == null || keys.size() != values.size()) {
            throw new IllegalArgumentException("Keys and Values cannot be null and must be the same size");
        }
        Map<K, V> newMap = new HashMap<K, V>();
        for (int i = 0; i < keys.size(); i++) {
            newMap.put(keys.get(i), values.get(i));
        }
        return newMap;
    }

    /**
     * Make sure the string starts with a forward slash but does not end with one; converts back-slashes to forward-slashes; if in String is null or empty, returns zero length string.
     */
    public static String cleanUpPathPrefix(String prefix) {
        if (prefix == null || prefix.length() == 0) return "";

        StringBuilder cppBuff = new StringBuilder(prefix.replace('\\', '/'));

        if (cppBuff.charAt(0) != '/') {
            cppBuff.insert(0, '/');
        }
        if (cppBuff.charAt(cppBuff.length() - 1) == '/') {
            cppBuff.deleteCharAt(cppBuff.length() - 1);
        }
        return cppBuff.toString();
    }

    /**
     * Removes all spaces from a string
     */
    public static String removeSpaces(String str) {
        return removeRegex(str, "[\\ ]");
    }

    public static String toHexString(byte[] bytes) {
        StringBuilder buf = new StringBuilder(bytes.length * 2);
        for (byte b : bytes) {
            buf.append(hexChar[(b & 0xf0) >>> 4]);
            buf.append(hexChar[b & 0x0f]);
        }
        return buf.toString();

    }

    public static String cleanHexString(String str) {
        StringBuilder buf = new StringBuilder();
        for (int i = 0; i < str.length(); i++) {
            if (str.charAt(i) != 32 && str.charAt(i) != ':') {
                buf.append(str.charAt(i));
            }
        }
        return buf.toString();
    }

    public static byte[] fromHexString(String str) {
        str = cleanHexString(str);
        int stringLength = str.length();
        if ((stringLength & 0x1) != 0) {
            throw new IllegalArgumentException("fromHexString requires an even number of hex characters");
        }
        byte[] b = new byte[stringLength / 2];

        for (int i = 0, j = 0; i < stringLength; i += 2, j++) {
            int high = convertChar(str.charAt(i));
            int low = convertChar(str.charAt(i + 1));
            b[j] = (byte) ((high << 4) | low);
        }
        return b;
    }

    private static char[] hexChar = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};

    public static int convertChar(char c) {
        if ('0' <= c && c <= '9') {
            return c - '0';
        } else if ('a' <= c && c <= 'f') {
            return c - 'a' + 0xa;
        } else if ('A' <= c && c <= 'F') {
            return c - 'A' + 0xa;
        } else {
            throw new IllegalArgumentException("Invalid hex character: [" + c + "]");
        }
    }

    public static char[] encodeInt(int i, int j, char digestChars[]) {
        if (i < 16) {
            digestChars[j] = '0';
        }
        j++;
        do {
            digestChars[j--] = hexChar[i & 0xf];
            i >>>= 4;
        } while (i != 0);
        return digestChars;
    }

    /**
     * Removes all non-numbers from str
     */
    public static String removeNonNumeric(String str) {
        return removeRegex(str, "[\\D]");
    }

    /**
     * Removes all numbers from str
     */
    public static String removeNumeric(String str) {
        return removeRegex(str, "[\\d]");
    }

    /**
     * @param str
     * @param regex Removes all matches of regex from a str
     */
    private static String removeRegex(String str, String regex) {
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(str);
        return matcher.replaceAll("");
    }

    /**
     * Add the number to the string, keeping (padding to min of original length)
     *
     * @return
     */
    public static String addToNumberString(String numberString, long addAmount) {
        if (numberString == null) return null;

        int origLength = numberString.length();
        long number = Long.parseLong(numberString);
        return padNumberString(Long.toString(number + addAmount), origLength);
    }

    public static String padNumberString(String numberString, int targetMinLength) {
        StringBuilder outStrBfr = new StringBuilder(numberString);
        while (targetMinLength > outStrBfr.length()) {
            outStrBfr.insert(0, '0');
        }
        return outStrBfr.toString();
    }


    /**
     * Translates various HTML characters in a string so that the string can be displayed in a browser safely
     * <p>
     * This function is useful in preventing user-supplied text from containing HTML markup, such as in a message board or
     * guest book application. The optional arguments doubleQuotes and singleQuotes allow the control of the substitution of
     * the quote characters.  The default is to translate them with the HTML equivalent.
     * </p>
     * The translations performed are: <ol>
     * <li>'&' (ampersand) becomes '&amp;'
     * <li>'"' (double quote) becomes '&quot;' when doubleQuotes is true.
     * <li>''' (single quote) becomes '&#039;' when singleQuotes is true.
     * <li>'<' (less than) becomes '&lt;'
     * <li>'>' (greater than) becomes '&gt;'
     * <li>\n (Carriage Return) becomes '&lt;br&gt;gt;'
     * </ol>
     */
    public static String htmlSpecialChars(String html, boolean doubleQuotes, boolean singleQuotes, boolean insertBR) {
        html = StringUtil.replaceString(html, "&", "&amp;");
        html = StringUtil.replaceString(html, "<", "&lt;");
        html = StringUtil.replaceString(html, ">", "&gt;");
        if (doubleQuotes) {
            html = StringUtil.replaceString(html, "\"", "&quot;");
        }
        if (singleQuotes) {
            html = StringUtil.replaceString(html, "'", "&#039;");
        }
        if (insertBR) {
            html = StringUtil.replaceString(html, "\n", "<br>");
        }

        return html;
    }

    public static String htmlSpecialChars(String html) {
        return htmlSpecialChars(html, true, true, true);
    }

    /**
     * double 去小数点
     *
     * @param dou
     * @return
     */
    public static String toString(double dou) {
        return String.valueOf(Integer.valueOf(String.valueOf(dou)));
    }

    /**
     * 编码格式
     *
     * @param s
     * @param enc
     * @return
     * @throws IOException
     * @throws Exception
     */
    public static String encode(String s, String enc) throws IOException, Exception {
        int caseDiff = 32;
        BitSet dontNeedEncoding = new BitSet(256);
        for (int i = 97; i <= 122; ++i)
            dontNeedEncoding.set(i);
        for (int i = 65; i <= 90; ++i)
            dontNeedEncoding.set(i);
        for (int i = 48; i <= 57; ++i)
            dontNeedEncoding.set(i);
        dontNeedEncoding.set(32);
        dontNeedEncoding.set(45);
        dontNeedEncoding.set(95);
        dontNeedEncoding.set(46);
        dontNeedEncoding.set(42);
        boolean needToChange = false;
        boolean wroteUnencodedChar = false;
        int maxBytesPerChar = 10;
        StringBuffer out = new StringBuffer(s.length());
        ByteArrayOutputStream buf = new ByteArrayOutputStream(maxBytesPerChar);
        OutputStreamWriter writer = new OutputStreamWriter(buf, enc);
        for (int i = 0; i < s.length(); ++i) {
            int c = s.charAt(i);
            if (dontNeedEncoding.get(c)) {
                if (c == 32) {
                    c = 43;
                    needToChange = true;
                }
                out.append((char) c);
                wroteUnencodedChar = true;
            } else {
                try {
                    if (wroteUnencodedChar) {
                        writer = new OutputStreamWriter(buf, enc);
                        wroteUnencodedChar = false;
                    }
                    writer.write(c);
                    if ((c >= 55296) && (c <= 56319) &&
                            (i + 1 < s.length())) {
                        int d = s.charAt(i + 1);

                        if ((d >= 56320) && (d <= 57343)) {
                            writer.write(d);
                            ++i;
                        }
                    }
                    writer.flush();
                } catch (IOException e) {
                    buf.reset();
                }
                byte[] ba = buf.toByteArray();
                for (int j = 0; j < ba.length; ++j) {
                    out.append('%');
                    char ch = Character.forDigit(ba[j] >> 4 & 0xF, 16);
                    if (Character.isLetter(ch))
                        ch = (char) (ch - caseDiff);
                    out.append(ch);
                    ch = Character.forDigit(ba[j] & 0xF, 16);
                    if (Character.isLetter(ch))
                        ch = (char) (ch - caseDiff);
                    out.append(ch);
                }
                buf.reset();
                needToChange = true;
            }
        }
        return ((needToChange) ? out.toString() : s);
    }

    /**
     * <p>创建时间：2010 2010-7-12 下午01:22:33</p>
     * <p>说明:得到当前系统时间</p>
     *
     * @return
     */
    public static Date getSystemDate() {
        return new Date();
    }

    /**
     * <p>创建时间：2010 2010-8-10 下午12:59:51</p>
     * <p>说明:得到当前系统时间</p>
     *
     * @return
     */
    public static String getSystemTime() {
        Date d = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(d.getTime());
    }

    /**
     * <p>创建时间：2010 2010-8-10 下午05:52:30</p>
     * <p>说明:字符串转换成日期 formatString可以是 yyyy-MM-dd HH:mm:ss 或 yyyy-MM-dd</p>
     *
     * @param dateString
     * @param formatString
     * @return
     */
    public static Date stringToDate(String dateString, String formatString) {
        Date returnValue = null;
        try {
            if (dateString != null && !"".equals(dateString)) {
                SimpleDateFormat formatter = new SimpleDateFormat(formatString);
                returnValue = formatter.parse(dateString);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return (returnValue);
    }

    /**
     * <p>创建时间：2010 2010-7-12 下午01:23:15</p>
     * <p>说明:数据类型转换Long2Int</p>
     *
     * @param ldata
     * @return
     */
    public static int Long2Int(long ldata) {
        return Integer.parseInt(String.valueOf(ldata));
    }

    /**
     * <p>创建时间：2010 2010-7-12 下午01:23:45</p>
     * <p>说明:数据类型转换Int2Long</p>
     *
     * @param intS
     * @return
     */
    public static long Int2Long(Integer intS) {
        return Long.parseLong(intS.toString());
    }

    /**
     * <p>创建时间：2010 2010-7-12 下午01:24:10</p>
     * <p>说明:数据类型转换Str2Long</p>
     *
     * @param str
     * @return
     */
    public static long Str2Long(String str) {
        return Long.parseLong(str.trim());
    }

    /**
     * <p>创建时间：2010 2010-7-12 下午01:24:24</p>
     * <p>说明:数据类型转换String2BigDecimal</p>
     *
     * @param str
     * @return
     */
    public static BigDecimal String2BigDecimal(String str) {
        BigDecimal bigDecimal = null;
        if (str != null && str.trim().length() != 0) {
            bigDecimal = new BigDecimal(str);
        }
        return bigDecimal;
    }

    /**
     * <p>创建时间：2010 2010-7-12 下午01:24:46</p>
     * <p>说明:数据类型转换</p>
     *
     * @param str
     * @return
     */
    public static int Str2Int(String str) {
        if (str == null || "".equals(str))
            return 0;
        return Integer.parseInt(str);
    }

    /**
     * <p>创建时间：2010 2010-7-12 下午01:25:21</p>
     * <p>说明:用指定的字符为需要补位的字符串补位</p>
     *
     * @param fillStr 用来补位的字符
     * @param oldStr  需要补位的字符串
     * @param length  补位后的总长度
     * @param place   补位位置:left or right
     * @return
     */
    public static String StrFill(String fillStr, String oldStr, int length, String place) {
        StringBuffer sb = new StringBuffer();
        if (!isBlank2(oldStr)) {
            if ("right".equals(place)) {
                sb.append(oldStr);
            }
            for (int i = 0; i < (length - oldStr.length()); i++) {
                sb.append(fillStr);
            }
            if ("left".equals(place)) {
                sb.append(oldStr);
            }
        }
        return sb.toString();
    }

    /**
     * <p>创建时间：2010 2010-7-12 下午01:26:11</p>
     * <p>说明:判断字符串是否为空,为空就返回true,不为空返回false</p>
     *
     * @param str
     * @return
     */
    public static boolean isBlank(Object str) {
        if (str == null) {
            return true;
        }
        if (String.valueOf(str).length() < 1) {
            return true;
        }
        return false;
    }

    /**
     * <p>创建时间：2010 2010-7-12 下午01:26:26</p>
     * <p>说明:判断字符串是否为空,匹配多个空格</p>
     *
     * @param str
     * @return
     */
    public static boolean isBlank2(String str) {
        if (str == null) {
            return true;
        }
        if (str.matches("\\s*")) {
            return true;
        } else {
            return false;
        }
    }


    /**
     * <p>创建时间：2010 2010-7-12 下午01:26:54</p>
     * <p>说明:转为UTF-8字符</p>
     *
     * @param str
     * @return
     */
    public static String toUTF8(String str) {
        if (str == null) {
            return null;
        }
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            if (c >= 0 && c <= 256) {
                sb.append(c);
            } else {
                try {
                    byte[] b = Character.toString(c).getBytes("UTF-8");
                    for (int j = 0; j < b.length; j++) {
                        int k = b[j];
                        if (k < 0) {
                            k = k + 256;
                        }
                        sb.append("%" + Integer.toHexString(k).toUpperCase());
                    }
                } catch (Exception e) {
                    System.out.println(e);
                }
            }
        }

        return sb.toString();
    }

    /**
     * <p>创建时间：2010 2010-7-12 下午01:28:37</p>
     * <p>说明:解UTF-8为8859_1</p>
     *
     * @param s
     * @return
     */
    public static String decodeUTF8(String s) {
        if (s == null)
            return "";

        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            switch (c) {
                case '+':
                    sb.append(' ');
                    break;
                case '%':
                    try {
                        //将16进制的数转化为十进制
                        sb.append((char) Integer.parseInt(
                                s.substring(i + 1, i + 3), 16));
                    } catch (NumberFormatException e) {
                        throw new IllegalArgumentException();
                    }
                    i += 2;
                    break;
                default:
                    sb.append(c);
                    break;
            }
        }

        String result = sb.toString();
        try {
            result = new String(result.getBytes("8859_1"), "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return result;
    }

    /**
     * <p>创建时间：2010 2010-7-12 下午01:29:33</p>
     * <p>说明:转换为SQL字符参数</p>
     *
     * @param str
     * @return
     */
    public static String toSqlParam(String str) {
        if (str == null) return "";
        str = str.trim();
        StringBuffer buf = new StringBuffer();
        buf.append("'");
        buf.append(str.replaceAll("'", "''"));
        buf.append("'");
        return buf.toString();
    }

    /**
     * <p>创建时间：2010 2010-7-12 下午01:30:25</p>
     * <p>说明:将数组转为指定符号分割的字符串</p>
     *
     * @param strs
     * @param split
     * @return
     */
    public static String getStringFromArray(String[] strs, String split) {
        if (StringUtil.isBlank(strs))
            return "";
        StringBuffer buf = new StringBuffer();
        for (int i = 0; i < strs.length; i++) {
            buf.append(strs[i]);
            if (i != (strs.length - 1)) {
                buf.append(split);
            }
        }
        return buf.toString();
    }

    /**
     * <p>创建时间：2010 2010-7-12 下午01:31:52</p>
     * <p>说明:中文字符串转换(解决中文乱码问题)</p>
     *
     * @param str
     * @return
     */
    public static String chineseStr(String str) {
        try {
            if (str == null) {
                return "";
            }
            String tempStr = str;
            byte[] tempArray = tempStr.getBytes("ISO8859-1");
            String temp = new String(tempArray, "UTF-8");
            return temp;
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return "";
    }

    public static String chineseStr2(String str) {
        try {
            if (str == null)
                return "";
            String tempStr = str;
            byte[] tempArray = tempStr.getBytes("ISO8859-1");
            String temp = new String(tempArray, "GBK");
            return temp;
        } catch (Exception ex) {
        }
        return "";
    }

    /**
     * <p>创建时间：2010 2010-7-22 上午10:43:08</p>
     * <p>说明:中文字符串转换</p>
     *
     * @param str
     * @return
     */
    public static String chineseEncode(String str) {
        String returnValue = "";
        try {
            if (str != null) {
                returnValue = URLEncoder.encode(str, "UTF8");
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return returnValue;
    }

    /**
     * <p>创建时间：2010 2010-7-22 上午10:43:18</p>
     * <p>说明:中文字符串还原</p>
     *
     * @param str
     * @return
     */
    public static String chineseDecode(String str) {
        String returnValue = "";
        try {
            if (str != null) {
                returnValue = URLDecoder.decode(str, "UTF8");
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return returnValue;
    }

    /**
     * <p>创建时间：2010 2010-7-12 下午01:32:08</p>
     * <p>说明:把null转换为 ""</p>
     *
     * @param temp
     * @return
     */
    public static String nullToStr(String temp) {
        if (temp == null) {
            temp = "";
        }
        return temp;
    }

    /**
     * <p>说明:把null转换为 0 </p>
     */
    public static long nullTo0(String temp) {
        long result;
        if (temp == null || "".equals(temp)) {
            result = 0;
        } else {
            result = Long.parseLong(temp);
        }
        return result;
    }

    /**
     * <p>创建时间：2010 2010-7-12 下午01:32:19</p>
     * <p>说明:把null转换为 指定字符（供特殊场景使用）</p>
     *
     * @param temp
     * @return
     */
    public static String nullToStr2(String temp, String defaultStr) {
        if (temp == null) {
            temp = defaultStr;
        }
        return temp.trim();
    }

    /**
     * <p>创建时间：2010 2010-7-12 下午01:33:19</p>
     * <p>说明:把null转换为 无（供特殊场景使用）</p>
     *
     * @param temp
     * @return
     */
    public static String nullToStr3(String temp) {
        if (temp == null) {
            temp = "无";
        }
        return temp.trim();
    }

    /**
     * <p>创建时间：2010 2010-7-12 下午01:34:10</p>
     * <p>说明:取得字符串长度(一个汉字为两个字符长度)</p>
     *
     * @param sourceStr
     * @return
     */
    public static long getStringLength(String sourceStr) {
        long returnValue = 0;
        if (sourceStr == null) {
            return (returnValue);
        }
        for (int i = 0; i < sourceStr.length(); i++) {
            char[] tempChar = sourceStr.substring(i, i + 1).toCharArray();
            if ((int) tempChar[0] > 255) {
                returnValue += 2;
            } else {
                returnValue++;
            }
        }
        return (returnValue);
    }

    /**
     * <p>创建时间：2010 2010-7-12 下午01:34:46</p>
     * <p>说明:取得重复次数的字符串</p>
     *
     * @param sourceStr
     * @param repeatTimes
     * @return
     */
    public static String getRepeatString(String sourceStr, long repeatTimes) {
        StringBuffer returnStr = new StringBuffer();
        for (int i = 0; i < repeatTimes; i++) {
            returnStr.append(sourceStr);
        }
        return (returnStr.toString());
    }

    /**
     * <p>创建时间：2010 2010-7-12 下午01:35:29</p>
     * <p>说明:取得指定长度的字符串,不足长度的以replaceString填充(一个汉字为两个字符长度)</p>
     *
     * @param sourceStr
     * @param specityLength
     * @param replaceString
     * @return
     */
    public static String getSpecifyLengthString(String sourceStr,
                                                long specityLength, String replaceString) {
        if (sourceStr == null) {
            return (getRepeatString(replaceString, specityLength));
        }
        long realLength = getStringLength(sourceStr);
        StringBuffer returnStr = new StringBuffer();
        if (realLength < specityLength) {
            returnStr.append(sourceStr);
            returnStr.append(getRepeatString(replaceString, specityLength
                    - realLength));
        } else {
            returnStr.append(getLeftString(sourceStr, specityLength,
                    replaceString));
        }
        return (returnStr.toString());
    }

    /**
     * <p>创建时间：2010 2010-7-12 下午01:35:50</p>
     * <p>说明:取得其中包含字符串中从左边算起指定数量的字符(一个汉字为两个字符长度)</p>
     *
     * @param sourceStr
     * @param leftLength
     * @param replaceString
     * @return
     */
    public static String getLeftString(String sourceStr, long leftLength,
                                       String replaceString) {
        StringBuffer returnStr = new StringBuffer();
        long tempLength = 0;
        for (int i = 0; i < sourceStr.length(); i++) {
            String tempStr = sourceStr.substring(i, i + 1);
            char[] tempChar = tempStr.toCharArray();
            if ((int) tempChar[0] > 255) {
                tempLength += 2;
            } else {
                tempLength++;
            }
            if (tempLength >= leftLength) {
                if (tempLength == leftLength) {
                    returnStr.append(tempStr);
                } else {
                    returnStr.append(getRepeatString(replaceString, tempLength
                            - leftLength));
                }
                break;
            }
            returnStr.append(tempStr);
        }
        return (returnStr.toString());
    }

    /**
     * <p>创建时间：2010 2010-7-12 下午01:36:05</p>
     * <p>说明:取得指定长度的字符串(一个汉字为两个字符长度,targetlength为汉字个数),超过以…代替</p>
     *
     * @param sourceString
     * @param targetlength
     * @return
     */
    public static String displayTitle(String sourceString, long targetlength) {
        String returnValue = "";
        if (sourceString != null) {
            if (getStringLength(sourceString) <= targetlength * 2) {
                returnValue = sourceString;
            } else {
                returnValue = getLeftString(sourceString,
                        (targetlength - 1) * 2, "")
                        + "…";
            }
        }
        return (returnValue);
    }

    /**
     * <p>创建时间：2010 2010-7-12 下午01:37:08</p>
     * <p>说明:URL中的中文字符串转换</p>
     *
     * @param str
     * @return
     */
    public static String URLEncode(String str) {
        String returnValue = "";
        try {
            if (str != null) {
                returnValue = URLEncoder.encode(str, "UTF-8");
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return returnValue;
    }


    /**
     * <p>创建时间：2010 2010-7-12 下午01:39:27</p>
     * <p>说明:取得指定长度的字符串</p>
     *
     * @param str
     * @param len byte
     * @return
     */
    public static String getLimitLengthString(String str, int len) {
        int counterOfDoubleByte = 0;
        byte[] b = null;
        try {
            b = str.getBytes("GBK");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        if (b.length <= len)
            return str;
        for (int i = 0; i < len; i++) {
            if (b[i] < 0)
                counterOfDoubleByte++;
        }
        if (counterOfDoubleByte % 2 == 0)
            try {
                return (new String(b, 0, len, "GBK")) + "...";
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        else
            try {
                return (new String(b, 0, len - 1, "GBK")) + "...";
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        return str;
    }

    /**
     * <p>创建时间：2010 2010-7-12 下午01:41:08</p>
     * <p>说明:转义字符</p>
     *
     * @param str
     * @return
     */
    public static String replaceInStr(String str) {
        str = str.replaceAll("&", "&amp;");
        str = str.replaceAll("\"", "&quot;");
        str = str.replaceAll("<", "&lt;");
        str = str.replaceAll(">", "&gt;");
        str = str.replaceAll("\n", "<br/>");
        str = str.replaceAll(" ", "&nbsp;");
        return str;
    }

    /**
     * <p>创建时间：2010 2010-7-12 下午01:41:46</p>
     * <p>说明:转义字符</p>
     *
     * @param str
     * @return
     */
    public static String replaceOutStr(String str) {
        str = str.replaceAll("<br/>", "\n");
        str = str.replaceAll("<br>", "\n");
        str = str.replaceAll("&lt;", "<");
        str = str.replaceAll("&gt;", ">");
        str = str.replaceAll("&nbsp;", " ");
        str = str.replaceAll("&amp;", "&");
        str = str.replaceAll("&quot;", "\"");
        return str;
    }

    /**
     * DT_S_CSRQ<BR>
     * 满足格式：<BR>
     * 1.YYYYMMDD<BR>
     * 2.YYYYMMDDHHmmSS =>YYYY年MM月DD日<BR>
     * DT_S_DATE8<BR>
     * 满足格式：<BR>
     * 1.DATE = > YYYY-MM-DD HH:mm:SS => YYYY年MM月DD日<BR>
     * DT_S_DATE<BR>
     * 满足格式：<BR>
     * 1.DATE = > YYYY-MM-DD HH:mm:SS => 1985年07月08日01时01分01秒<BR>
     * DT_S_RQ14<BR>
     * 满足格式：<BR>
     * 1.YYYYMMDDHHmmSS =>1985年07月08日01时01分01秒<BR>
     * 2.YYYY-MM-DD HH:mm:SS => 1985年07月08日01时01分01秒<BR>
     * 3.YYYY-MM-DD => 1985年07月08日<BR>
     * <p>创建时间：2010 2010-7-12 下午01:44:56</p>
     * <p>说明:字符串转换为年月日格式的字符串</p>
     *
     * @param str
     * @param format
     * @return
     */
    public static String getDate(String str, String format) {

        if (str == null || str.equals("")) {
            return "";
        } else {
            if (format.equals("DT_S_CSRQ")) {
                str = str.substring(0, 4) + "年"
                        + str.substring(4, 6) + "月"
                        + str.substring(6, 8) + "日";
            } else if (format.equals("DT_S_DATE8")) {
                str = str.substring(0, 4) + "年"
                        + str.substring(5, 7) + "月"
                        + str.substring(8, 10) + "日";
            } else if (format.equals("DT_S_DATE")) {
                str = str.substring(0, 4) + "年"
                        + str.substring(5, 7) + "月"
                        + str.substring(8, 10) + "日"
                        + str.substring(11, 13) + "时"
                        + str.substring(14, 16) + "分"
                        + str.substring(17, 19) + "秒";
            } else if (format.equals("DT_S_RQ14")) {
                char[] ch = str.toCharArray();
                if ((Character.isDigit(ch[4]))) {
                    if (str.length() > 12) {
                        str = str.substring(0, 4) + "年"
                                + str.substring(4, 6) + "月"
                                + str.substring(6, 8) + "日"
                                + str.substring(8, 10) + "时"
                                + str.substring(10, 12) + "分"
                                + str.substring(12, 14) + "秒";
                    } else if (str.length() == 12) {
                        str = str.substring(0, 4) + "年"
                                + str.substring(4, 6) + "月"
                                + str.substring(6, 8) + "日"
                                + str.substring(8, 10) + "时"
                                + str.substring(10, 12) + "分";
                    } else {
                        str = str.substring(0, 4) + "年"
                                + str.substring(4, 6) + "月"
                                + str.substring(6, 8) + "日";
                    }
                } else if (str.length() > 18) {
                    str = str.substring(0, 4) + "年"
                            + str.substring(5, 7) + "月"
                            + str.substring(8, 10) + "日"
                            + str.substring(11, 13) + "时"
                            + str.substring(14, 16) + "分"
                            + str.substring(17, 19) + "秒";
                } else {
                    str = str.substring(0, 4) + "年"
                            + str.substring(5, 7) + "月"
                            + str.substring(8, 10) + "日";
                }
            }
        }
        return str;
    }

    /**
     * <p>创建时间：2010 2010-7-12 下午01:46:24</p>
     * <p>说明:DATE数据字符串转化为8位日期格式</p>
     *
     * @param str 8位
     * @return
     */
    public static String getDate8(String str) {

        if (str == null || str.equals("")) {
            return "";
        } else {
            str = str.substring(0, 4) + "年"
                    + str.substring(4, 6) + "月"
                    + str.substring(6, 8) + "日";
        }
        return str;
    }

    /**
     * <p>创建时间：2010 2010-7-12 下午02:01:23</p>
     * <p>说明:DATE数据字符串转化为8位日期格式 （分隔符号指定）</p>
     *
     * @param str
     * @param formatFlag
     * @return
     */
    public static String getDate8ByFormat(String str, String formatFlag) {

        if (str == null || str.equals("")) {
            return "";
        } else {
            str = str.substring(0, 4) + formatFlag
                    + str.substring(4, 6) + formatFlag
                    + str.substring(6, 8);
        }
        return str;
    }

    /**
     * <p>创建时间：2010 2010-7-12 下午01:47:46</p>
     * <p>说明:将字符数组转换为格式如: ('aa','bb','cc')</p>
     *
     * @param ids
     * @return
     */
    public static String getSqlFromArray(String[] ids) {
        if (ids == null || ids.length == 0) {
            return "";
        }
        StringBuffer buf = new StringBuffer("(");
        for (int i = 0, j = ids.length, k = j - 1; i < j; i++) {
            buf.append(StringUtil.toSqlParam(ids[i]));
            if (k != 0 && i != k) {
                buf.append(",");
            }
        }
        buf.append(")");
        return buf.toString();
    }

    /**
     * <p>创建时间：2010 2010-7-12 下午01:48:10</p>
     * <p>说明:序列化字符数组，转换为字符: aaa,bbb,ccc</p>
     *
     * @param arrays
     * @param regex
     * @return
     */
    public static String serializeArray(String[] arrays, String regex) {
        if (arrays == null) {
            return "";
        }
        StringBuffer buf = new StringBuffer();
        for (int i = 0, j = arrays.length, k = j - 1; i < j; i++) {
            buf.append(arrays[i]);
            if (k != 0 && i != k) {
                buf.append(regex);
            }
        }
        return buf.toString();
    }

    /**
     * <p>创建时间：2010 2010-7-12 下午01:48:45</p>
     * <p>说明:根据身份证取得性别</p>
     *
     * @param sfzh 18位
     * @return
     */
    public static String getGenderBySfzh(String sfzh) {
        if (StringUtil.isBlank(sfzh))
            return null;
        if (sfzh.length() < 18)
            return null;
        String s = String.valueOf(sfzh.charAt(16));
        int i = Integer.parseInt(s);
        return (i % 2 == 0) ? "女" : "男";
    }

    /**
     * <p>创建时间：2010 2010-7-12 下午01:59:03</p>
     * <p>说明:根据身份证取得出生日期</p>
     *
     * @param sfzh 18位
     * @return
     */
    public static String getBirtyBySfzh(String sfzh) {
        if (StringUtil.isBlank(sfzh))
            return null;
        if (sfzh.length() < 18)
            return null;
        String temp = sfzh.substring(6, 14);
        //return StringUtil.getDate8ByFormat(temp,"-");
        return StringUtil.getDate8(temp);
    }

    /**
     * <p>创建时间：2010 2010-7-12 下午01:49:57</p>
     * <p>说明:将字符解析为字符数组</p>
     *
     * @param str
     * @param regex
     * @return
     */
    public static String[] unSerializeArray(String str, String regex) {
        if (StringUtil.isBlank2(str)) {
            return new String[]{};
        }
        return str.split(regex);
    }

    /**
     * <p>创建时间：2010 2010-8-10 下午02:58:37</p>
     * <p>说明:取得两个日期之间的时差(date1大于date2时, 切除小数;date1小于date2时,小数进位)</p>
     * <p>说明:返回值(数组[0]= 1当date1>=date2 =2当date1<date2; 数组[1]=时间差距; 数组[2]=单位)</p>
     *
     * @param date1
     * @param date2
     * @return
     */
    public static String[] getTimeInterval(Date date1, Date date2) {
        String[] returnValue = new String[3];
        long minute = (long) Math
                .floor((date1.getTime() - date2.getTime()) / 60000);
        if (minute >= 0)
            returnValue[0] = "1";
        else
            returnValue[0] = "2";
        if (Math.abs(minute) >= 60) {
            long hour = (long) Math.floor(minute / 60.0);
            if (Math.abs(hour) >= 24) {
                long day = (long) Math.floor(hour / 24.0);
                returnValue[1] = "" + Math.abs(day);
                returnValue[2] = "天";
            } else {
                returnValue[1] = "" + Math.abs(hour);
                returnValue[2] = "小时";
            }
        } else {
            returnValue[1] = "" + Math.abs(minute);
            returnValue[2] = "分";
        }
        return (returnValue);
    }

    /**
     * <p>创建时间：2010 2010-8-10 下午05:49:15</p>
     * <p>说明:计算两个日期之间相差的天数  </p>
     *
     * @param date1
     * @param date2
     * @return
     */
    public static int daysBetween(Date date1, Date date2) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date1);
        long time1 = cal.getTimeInMillis();
        cal.setTime(date2);
        long time2 = cal.getTimeInMillis();
        long between_days = (time2 - time1) / (1000 * 3600 * 24);
        return Integer.parseInt(String.valueOf(between_days));
    }

    /**
     * <p>创建时间：2010 2010-8-10 下午05:49:23</p>
     * <p>说明:计算两个日期之间相差的天数 (除星期六和星期天)</p>
     *
     * @param sDate
     * @param eDate
     * @return
     */
    public static int daysOfTwo(Date sDate, Date eDate) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(sDate);
        int day1 = calendar.get(Calendar.DAY_OF_YEAR);
        calendar.setTime(eDate);
        int day2 = calendar.get(Calendar.DAY_OF_YEAR);
        //求出两日期相隔天数
        int days = day2 - day1;
        //除去星期六、天
        days = (days - days % 7) * 5 / 7 + ((days % 7 > 5) ? 5 : days % 7);
        return days;
    }

    /**
     * <p>创建时间：2010 2010-8-23 上午09:48:13</p>
     * <p>说明:二进制转字符串</p>
     *
     * @param b
     * @return
     */
    public static String byte2hex(byte[] b) {
        StringBuffer sb = new StringBuffer();
        String stmp = "";
        for (int n = 0; n < b.length; n++) {
            stmp = Integer.toHexString(b[n] & 0XFF);
            if (stmp.length() == 1) {
                sb.append("0" + stmp);
            } else {
                sb.append(stmp);
            }
        }
        return sb.toString();
    }

    /**
     * <p>创建时间：2010 2010-8-23 上午09:48:33</p>
     * <p>说明:字符串转二进制</p>
     *
     * @param str
     * @return
     */
    public static byte[] hex2byte(String str) {
        if (str == null)
            return null;
        str = str.trim();
        int len = str.length();
        if (len == 0 || len % 2 == 1)
            return null;
        byte[] b = new byte[len / 2];
        try {
            for (int i = 0; i < str.length(); i += 2) {
                b[i / 2] = (byte) Integer
                        .decode("0X" + str.substring(i, i + 2)).intValue();
            }
            return b;
        } catch (Exception e) {
            return null;
        }
    }

    /**
     * <p>创建时间：2010 Aug 20, 2010 4:38:49 PM</p>
     * <p>说明:过滤掉HTML所有标签</p>
     *
     * @param inputString
     * @return
     */
    public static String html2Text(String inputString) {
        String htmlStr = inputString; //含html标签的字符串
        String textStr = "";
        Pattern p_script;
        Matcher m_script;
        Pattern p_style;
        Matcher m_style;
        Pattern p_html;
        Matcher m_html;

        Pattern p_html1;
        Matcher m_html1;

        try {
            String regEx_script = "<[\\s]*?script[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?script[\\s]*?>"; //定义script的正则表达式{或<script[^>]*?>[\\s\\S]*?<\\/script> }
            String regEx_style = "<[\\s]*?style[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?style[\\s]*?>"; //定义style的正则表达式{或<style[^>]*?>[\\s\\S]*?<\\/style> }
            String regEx_html = "<[^>]+>"; //定义HTML标签的正则表达式
            String regEx_html1 = "<[^>]+";
            p_script = Pattern.compile(regEx_script, Pattern.CASE_INSENSITIVE);
            m_script = p_script.matcher(htmlStr);
            htmlStr = m_script.replaceAll(""); //过滤script标签

            p_style = Pattern.compile(regEx_style, Pattern.CASE_INSENSITIVE);
            m_style = p_style.matcher(htmlStr);
            htmlStr = m_style.replaceAll(""); //过滤style标签

            p_html = Pattern.compile(regEx_html, Pattern.CASE_INSENSITIVE);
            m_html = p_html.matcher(htmlStr);
            htmlStr = m_html.replaceAll(""); //过滤html标签

            p_html1 = Pattern.compile(regEx_html1, Pattern.CASE_INSENSITIVE);
            m_html1 = p_html1.matcher(htmlStr);
            htmlStr = m_html1.replaceAll(""); //过滤html标签


            textStr = htmlStr;

        } catch (Exception e) {
            System.err.println("Html2Text: " + e.getMessage());
        }
        return textStr;
    }

    /**
     * 密码复杂度验证
     *
     * @param val
     * @return
     */
    public static boolean checkStrong(String val) {
        int modes = 0;
        if (val.length() < 8) return false;
        if (Pattern.compile("\\d").matcher(val).find()) modes++;      //数字
        if (Pattern.compile("[a-z]").matcher(val).find()) modes++;    //小写
        if (Pattern.compile("[A-Z]").matcher(val).find()) modes++;    //大写
        if (Pattern.compile("\\W").matcher(val).find()) modes++;      //特殊字符
        if (val.length() > 25) return false;
        if (modes == 4) {
            return true;
        } else {
            return false;
        }
    }

    public static void main(String[] args) {
        String str = "admin"+":"+"990716";
        System.out.println(Base64.getEncoder().encodeToString(str.getBytes(StandardCharsets.UTF_8)));
    }
}
